@using BTCPayServer.Services
@model LightningSettingsViewModel
@inject LightningClientFactoryService LightningClientFactoryService
@inject BTCPayNetworkProvider NetworkProvider
@{
    ViewData.SetLayoutModel(new LayoutModel($"{nameof(StoreNavPages.LightningSettings)}-{Model.CryptoCode}", StringLocalizer["{0} Lightning Settings", Model.CryptoCode])
        .SetCategory(WellKnownCategories.ForLightning(Model.CryptoCode)));
}

<form method="post">
    <div class="sticky-header">
        <h2>@ViewData["Title"]</h2>
		<button id="page-primary" name="command" type="submit" value="save" class="btn btn-primary" text-translate="true">Save</button>
    </div>
    <partial name="_StatusMessage" />
    <div class="row">
        <div class="col-xl-8 col-xxl-constrain">
            <div class="mb-5">
                <div class="text-break mb-3">
                    <span class="me-3" id="NodeType">@StringLocalizer["{0} Node", Model.LightningNodeType]</span>
                    @if (Model.LightningNodeType != LightningNodeType.Internal)
                    {
                        <span class="me-3" id="CustomNodeInfo">
                            @try
                            {
                                var client = LightningClientFactoryService.Create(Model.ConnectionString, NetworkProvider.GetNetwork<BTCPayNetwork>(Model.CryptoCode));
								<span>@client.GetDisplayName(Model.ConnectionString)</span>
								var uri = client.GetServerUri(Model.ConnectionString);
                                if (uri is not null)
                                {
                                    <span>(@uri.Host)</span>
                                }
                            }
                            catch (Exception)
                            {
                                @Model.ConnectionString
                            }
                        </span>
                    }

                    <a class="me-3"
                       asp-controller="UIPublicLightningNodeInfo"
                       asp-action="ShowLightningNodeInfo"
                       asp-route-cryptoCode="@Model.CryptoCode"
                       asp-route-storeId="@Model.StoreId"
                       target="_blank"
                       id="PublicNodeInfo"
                       text-translate="true">
                        Public Node Info
                    </a>
                    <a asp-controller="UIStores" asp-action="SetupLightningNode" asp-route-storeId="@Model.StoreId" asp-route-cryptoCode="@Model.CryptoCode" id="SetupLightningNodeLink" text-translate="true">
                        Change connection
                    </a>
                </div>

                <div class="d-flex align-items-center">
                    <input type="checkbox" asp-for="Enabled" class="btcpay-toggle me-3" id="@($"{Model.CryptoCode}LightningEnabled")" />
                    <label asp-for="Enabled" class="form-check-label"></label>
                </div>

                <div class="text-start">
                    <h3 class="mt-5 mb-3" text-translate="true">Payment</h3>
                    <div class="form-check my-3">
                        <input asp-for="LightningAmountInSatoshi" type="checkbox" class="form-check-input"/>
                        <label asp-for="LightningAmountInSatoshi" class="form-check-label"></label>
                    </div>
                    <div class="form-check my-3">
                        <input asp-for="LightningPrivateRouteHints" type="checkbox" class="form-check-input"/>
                        <label asp-for="LightningPrivateRouteHints" class="form-check-label"></label>
                    </div>
                    <div class="form-check my-3">
                        <input asp-for="OnChainWithLnInvoiceFallback" type="checkbox" class="form-check-input"/>
                        <label asp-for="OnChainWithLnInvoiceFallback" class="form-check-label"></label>
                        <a href="https://bitcoinqr.dev/" target="_blank" rel="noreferrer noopener">
                            <vc:icon symbol="info" />
                        </a>
                    </div>
                    <div class="form-group mt-3">
                        <label asp-for="LightningDescriptionTemplate" class="form-label"></label>
                        <input asp-for="LightningDescriptionTemplate" class="form-control"/>
                        <span asp-validation-for="LightningDescriptionTemplate" class="text-danger"></span>
                        <div class="form-text" html-translate="true">Available placeholders: <code>{StoreName} {ItemDescription} {OrderId}</code></div>
                    </div>

                    <h3 class="mt-5 mb-3" id="ln-url" text-translate="true">LNURL</h3>
                    <div class="form-group d-flex align-items-center">
                        <input asp-for="LNURLEnabled" type="checkbox" class="btcpay-toggle me-3" data-bs-toggle="collapse" data-bs-target="#LNURLSettings" aria-expanded="@Model.LNURLEnabled" aria-controls="LNURLSettings"/>
                        <label asp-for="LNURLEnabled" class="form-check-label"></label>
                    </div>

                    <div class="collapse @(Model.LNURLEnabled ? "show" : "")" id="LNURLSettings">
                        <div class="form-group">
                            <label class="form-group d-flex align-items-center">
                                <input type="checkbox" asp-for="LNURLBech32Mode" class="btcpay-toggle me-3" />
                                <div>
                                    <label asp-for="LNURLBech32Mode" class="form-check-label"></label>
                                    <span asp-validation-for="LNURLBech32Mode" class="text-danger"></span>
                                    <div class="form-text" text-translate="true">For wallet compatibility: Bech32 encoded (classic) vs. cleartext URL (upcoming)</div>
                                </div>
                            </label>
                        </div>
                        <div class="form-group mb-3">
                            <div class="d-flex align-items-center">
                                <input type="checkbox" asp-for="LUD12Enabled" class="btcpay-toggle me-3" />
                                <label asp-for="LUD12Enabled" class="form-check-label"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

@section PageFootContent {
    <partial name="_ValidationScriptsPartial"/>
}
